#ifndef __MACRO_H__
#define __MACRO_H__

#include <string.h>
#include <assert.h>

#include "util.h"
#include "log.h"

#if defined __GNUG__ || defined __llvm__
/// LIKCLY 宏的封装, 告诉编译器优化,条件大概率成立
#define SYLAR_LIKELY (x)            __builtin_expect(!!(x), 1)
/// LIKCLY 宏的封装, 告诉编译器优化,条件大概率不成立
#define SYLAR_UNLIKELY(x)           __builtin_expect(!!(x), 0)
#else
#define  SYLAR_LIKELY(x)        (x)
#define  SYLAR_UNLIKELY(x)      (x)
#endif


/// !false = true ==> !!true = true
#define SYLAR_ASSERT(x) \
        if (SYLAR_UNLIKELY(!(x)))   {\
            SYLAR_LOG_ERROR(SYLAR_LOG_ROOT()) << "ASSERTION: " #x\
            << "\n bracktrace:\n" \
            << sylar::BacktraceToStrig(100, 2, "    ");\
            assert(x); \
        }

#define SYLAR_ASSERT2(x, w)\
            if (SYLAR_UNLIKELY(!(x)))   {\
            SYLAR_LOG_ERROR(SYLAR_LOG_ROOT()) << "ASSERTION: " #x\
            << "\n " << #w \
            << "\n bracktrace:\n" \
            << sylar::BacktraceToStrig(100, 2, "    ");\
            assert(x); \
        }


#endif